#pragma once

#include <vector>
#include<bitset>

namespace xyx
{
	//非类型模板参数，开多少位的空间
	template<size_t N>
	class BitSet
	{
	public:
		BitSet()
		{
			_table.resize(N / 32 + 1);
		}

		void set(size_t x)
		{
			size_t i = x / 32;
			size_t j = x % 32;
			_table[i] |= (1 << j);
		}
		
		void reset(size_t x)
		{
			size_t i = x / 32;
			size_t j = x % 32;
			_table[i] &= (~(1 << j));
		}
		
		bool check(size_t x)
		{
			size_t i = x / 32;
			size_t j = x % 32;
		
			return _table[i] & (1 << j);
		}
	private:
		vector<int> _table;
	};
}



template<size_t N>
class tbitset
{
public:
	void Set(size_t x)
	{
		//从没出现过就修改成01
		// 00 -> 01
		if (!_bs1.test(x) && !_bs2.test(x))
		{
			_bs2.set(x);
		} // 01 - 10 出现次数大于1次
		else if (!_bs1.test(x) && _bs2.test(x))
		{
			_bs1.set(x);
			_bs2.reset(x);
		}
	}

	bool Test(size_t x)
	{
		// 01 表示出现一次
		return !_bs1.test(x) && _bs2.test(x);
	}
private:
	bitset<N> _bs1;
	bitset<N> _bs2;
};
